<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let p1 = new Promise((resolve,reject)=>{
            setTimeout(() => {
                reject('p1 failed')
            }, 1000);
        })

        let p2 = new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve('p2 success')
            }, 2000);
        })

        let p3 = new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve('p3 success')
            }, 3000);
        })

        async function demo(){
            try {
                // 注意里面只要有一个promise是失败的，程序就会停在那里。
                let result1 = await p1
                console.log(result1);
                let result2 = await p2
                console.log(result2);
                let result3 = await p3
                console.log(result3);
            } catch (error) {
                console.log(error);
            }
        }
        demo()
    </script>
</body>
</html>